﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Benlai.Dac.Mongo;
using MongoDB.Driver;
using Benlai.Model.Common;

namespace Benlai.Dac.Common
{
    public class TreeDac : MongoHandler<TreeModel>
    {
        public TreeDac()
        {
            DBName = "houtai";
            Name = "tree";
            SortPropertyName = "ordernum";
            IsDescending = false;
        }

        public TreeModel GetByID(string id)
        {
            return FindByID(id);
        }

        public List<TreeModel> Get(string no)
        {
            return GetModel(new { no = no }).ToList<TreeModel>();
        }

        public void Set(TreeModel model)
        {
            if (string.IsNullOrEmpty(model.Id))
            {
                Insert(model);
            }
            else
            {
                Update(model, model.Id);
            }
        }

        public List<TreeModel> GetList(int level)
        {
            int recordCount = 0;
            return GetModel(new { level = level }, 1, 20000, out recordCount).ToList<TreeModel>();
        }
        public List<TreeModel> GetList(int level, int type)
        {
            int recordCount = 0;
            return GetModel(new { level = level, type = type }, 1, 20000, out recordCount).ToList<TreeModel>();
        }
        public List<TreeModel> GetList(int type, int pageIndex, int pageSize, out int recordCount)
        {
            return GetModel(new { type = type }, pageIndex, pageSize, out recordCount).ToList<TreeModel>();
        }
        public List<TreeModel> GetList(int pageIndex, int pageSize, out int recordCount)
        {
            return GetModel(pageIndex, pageSize, out recordCount).ToList<TreeModel>();
        }
    }
}
